/**
 * Created by dongp on 2018/1/20.
 */
$(function (){
    iniList();
    editRole();
    cancelRole();

});

function iniList() {
    var obj = $("#roleList").datagrid("getSelected");
    if(Kit.isEmpty(obj)) {
        return false;
    }

    $("#id").val(obj.id);
    $("#roleName").val(obj.roleName);
    $("#roleValue").val(obj.roleValue);
    $("#privilegeId").val(obj.privilegeId);
}


function editRole(){

    $("#editRole_save").on("click",function (){
        if(Kit.isEmpty($("#roleName").val())) {
            $.messager.alert("帮助提示","请输入角色名");
            return false;
        }
        if(Kit.isEmpty($("#roleValue").val())) {
            $.messager.alert("帮助提示","请输入角色值");
            return false;
        }
        var sendData = {
            id:$("#id").val(),
            roleName:$("#roleName").val(),
            roleValue: $("#roleValue").val()
        }

        ui.request({
            url:"/admin/role/modify",
            data:sendData,
            success:function (rtn) {
                console.log(rtn)
                if(rtn.code != undefined && rtn.code !== "0000"){
                    $.messager.alert(rtn.msg,rtn.desc);
                }
                $('#win').window('close');
                $("#roleList").datagrid("reload",{});
            }
        })
    });
}

function cancelRole() {
    $("#editRole_cancel").on("click",function (){
        $('#win').window('close');
    });
}